<?php
/*
 * @Descripttion: 
 * @Author: dedeye
 * @Date: 2020-02-25 23:31:27
 * @LastEditors: dedeye
 * @LastEditTime: 2020-03-01 15:49:30
 */

namespace app\admin\validate;

use think\Validate;

class AdminValidate extends Validate
{
        /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'captcha'=>'require|captcha',
        'id' => 'require|number',
        'username' => 'require|length:5,15|alphaDash',
        'mykey' => 'require|token:mykey',
        'nickname' => 'require|max:32',
        'password' => 'require|length:6,18|alphaDash',
        'repassword'=>'require|confirm:password',
        'status' => 'require|in:0,1',
        'page' => 'number',
        'limit' => 'number'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'captcha.require' => '验证码不能为空',
        'captcha.captcha' => '验证码错误',
        'username.require' => '账号不能为空',
        'username.length' => '账号长度为5~15个字符',
        'username.alphaDash' => '账号必须为英文，数字，下划线_以及横线-',
        'mykey.token' => '提交无效',
        'password.require' => '密码不能为空',
        'password.length' => '密码长度为6~18个字符',
        'password.alphaDash' => '密码必须为英文，数字，下划线_以及横线-',
        'repassword.require' => '确认密码不能为空',
        'repassword.confirm' => '确认密码错误',
    ];

    protected $scene = [
        'login' => ['captcha', 'username', 'password'],
        'repassword' => ['password', 'repassword'],
        'edit' => ['id', 'username', 'nickname', 'status', 'mykey'],
    ];

    public function sceneAdd ()
    {
    	return $this->only(['username', 'nickname', 'password', 'repassword', 'status'])
        	->append('username|用户名重复', 'unique:admin');
    }
    public function sceneSelect ()
    {
    	return $this->only(['username', 'nickname', 'page', 'limit'])
                ->remove('username', ['require', 'length'])
                ->remove('nickname', ['require', 'length']);
    }
}
